url = 'https://www.acwing.com/problem/content/909/'


st, ed = map(int, input().split())
n = int(input())
# 输入每个区间的左右端点
ranges = []
for i in range(n):
    l, r = map(int, input().split())
    ranges.append((l, r))

# 按左端点从小到大排序
ranges.sort()

# 初始化结果为 0，success 表示是否能到达 ed
res, success = 0, False
i = 0
for i in range(n):
    # 当前区间能到达 st 的最远位置
    r = -2e9
    j = i
    while j < n and ranges[j][0] <= st:
        r = max(r, ranges[j][1])
        j += 1

    # 如果当前区间不能到达 st，说明无法到达 ed
    if r < st:
        res = -1
        break

    # 统计步数
    res += 1
    if r >= ed:
        success = True
        break

    st = r
    i = j - 1
    # if t<=i:
    #     i+=1

# 如果无法到达 ed，或者区间数量为 0，输出 -1
if not success or n == 0:
    res = -1
print(res)
